﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Design;

namespace DataManage
{
    public class RespResult<T>
    {
        public int Code { get; set; }
        public string Message { get; set; }
        public RespBody<T> Body { get; set; }

        /// <summary>
        /// 包装返回码，兼容Code与Body对象中的ReturnCode
        /// </summary>
        /// <returns></returns>
        public int GetCode()
        {
            if (Body == null)
            {
                if (this.Code < 1) this.Message += $"code={this.Code}";
                return this.Code;
            }
            else
            {
                this.Message = $"上位机发送指令执行失败，应答帧ID：0x[{Body.CommandId.ToString("X8")}],错误码：{this.Code}";
                return 1;
            }
        }
    }
    public class RespBody<T>
    {
        public uint CommandId { get; set; }      //应答ID
        public T Data { get; set; }
    }
}
